/*
 * @Author: szx
 * @Date: 2021-12-26 13:38:02
 * @LastEditTime: 2021-12-26 13:40:47
 * @Description:
 * @FilePath: \leetcode\500-599\538\538.js
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var convertBST = function (root) {
    let pre = 0;
    const ReverseInOrder = (cur) => {
        if (cur) {
            ReverseInOrder(cur.right);
            cur.val += pre;
            pre = cur.val;
            ReverseInOrder(cur.left);
        }
    };
    ReverseInOrder(root);
    return root;
};
